package cn.me.alphamq.common.entity.req;

import cn.me.alphamq.common.constant.GlobalConstant;
import cn.me.alphamq.common.entity.BaseMsg;
import cn.me.alphamq.common.util.AssertUtil;
import cn.me.alphamq.common.util.DelayTimeUtil;

/**
 * 生产者生产延迟消息的请求
 *
 * @author f
 */
public class PushDelayMsgReq extends BaseMsg {

    /**
     * 消息的主题
     */
    private String topic;

    /**
     * 放入消息的队列 id，默认值是 -1，如果没有传递，则会在写入数据时默认写到 0 号队列
     */
    private int queueId;

    /**
     * 消息的主体
     */
    private byte[] body;

    /**
     * 处理的时间，单位：ms，= 当前时间 + 延迟时间 * 1000
     */
    private long executeTime;

    public PushDelayMsgReq() {
    }

    /**
     * 构造一条延迟消息
     *
     * @param topic     延迟消息的主题
     * @param queueId   延迟消息存放的队列 id
     * @param body      延迟消息的主体
     * @param delayTime 延迟时间，范围：[1, 3600]，单位：s
     */
    public PushDelayMsgReq(String topic, int queueId, byte[] body, int delayTime) {
        this.topic = topic;
        this.queueId = queueId;
        this.body = body;
        AssertUtil.isInClosedRange(delayTime, 1, GlobalConstant.MAX_DELAY_TIME, GlobalConstant.INCORRECT_DELAY_TIME_MSG);
        this.executeTime = DelayTimeUtil.getExecuteTime(delayTime);
    }

    public String getTopic() {
        return topic;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public int getQueueId() {
        return queueId;
    }

    public void setQueueId(int queueId) {
        this.queueId = queueId;
    }

    public byte[] getBody() {
        return body;
    }

    public void setBody(byte[] body) {
        this.body = body;
    }

    public long getExecuteTime() {
        return executeTime;
    }

    public void setExecuteTime(long executeTime) {
        this.executeTime = executeTime;
    }
}
